﻿Imports System.IO
Imports System.Data.SqlClient
Public Class Administrateur
    Public login As String
    Public pass As String
    Public listCompte As ArrayList
    Public Sub New()
        Dim cmd As SqlCommand = New SqlCommand("select * from Administrateur", Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        Partager.dr.Read()
        Me.login = Partager.dr("login")
        Me.pass = Partager.dr("pass")
        Partager.dr.Close()
    End Sub
    Public Sub AjouterCompter(ByVal cmpt As Compte)
        Dim cmd As SqlCommand = New SqlCommand("insert into Compte values(@useer" & _
        ",@passe,'" & cmpt.nom & "',@type,@Remarque,GETDATE())", Partager.con)

        cmd.Parameters.Add("@useer", SqlDbType.VarChar).Value = cmpt.user
        cmd.Parameters.Add("@passe", SqlDbType.VarChar).Value = cmpt.passe
        cmd.Parameters.Add("@Nom", SqlDbType.VarChar).Value = cmpt.nom
        cmd.Parameters.Add("@type", SqlDbType.Bit).Value = cmpt.type
        cmd.Parameters.Add("@Remarque", SqlDbType.VarChar).Value = cmpt.remarque

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        remplirListCompte()
    End Sub

    Public Sub modifierCompter(ByVal cmpt As Compte)
        Dim cmd As New SqlClient.SqlCommand("update Compte set Useer =@Usser'" & _
                                            ",Passe =@Passe where id = " & cmpt.Id, Partager.con)

        cmd.Parameters.Add("@Usser", SqlDbType.VarChar).Value = cmpt.user
        cmd.Parameters.Add("@Passe", SqlDbType.VarChar).Value = cmpt.passe

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        remplirListCompte()
    End Sub

    Public Sub supprimerCompter(ByVal cmpt As Compte)
        Dim cmd As SqlCommand = New SqlCommand("delete From Compte where id= " & cmpt.Id, Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()
        remplirListCompte()
    End Sub

    Public Sub remplirListCompte()
        Me.listCompte = New ArrayList
        Dim cmd As SqlCommand = New SqlCommand("select * from Compte", Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        If Partager.dr.HasRows Then
            While Partager.dr.Read

                Partager.utilist = New Compte(Partager.dr("Id"), Partager.dr("Useer"), Partager.dr("Passe"), _
                                          Partager.dr("Nom_Complet"), Partager.dr("typee"), Partager.dr("Remarque"))
                Me.listCompte.Add(Partager.utilist)
            End While
        End If
        Partager.dr.Close()

        For Each cmpt In Me.listCompte
            cmpt.remplirLstcmptFrm()
        Next
    End Sub
End Class
